<template>
	<!-- 主播房间列表 -->
	<view>
		<!-- <view class="py-2 pm-2 bg-light" v-for="(item,index) in list" :key="index" @click="goLive(item.index)">
				{{item.title}}
		</view> -->
		<view class="my-2"  v-for="(item,index) in list" :key="index" @click="goLive(item.id)">
			<view class="flex align-center px-3 bg-light rounded" style="height: 100rpx;">
				<image :src="item.cover||'../../static/demo/1.jpg'" style="width: 80rpx;height: 80rpx;"></image>
				<view class="ml-3">
					{{item.title}}
				</view>
			</view>
		</view>
		<view class="flex align-center px-3 bg-light rounded" style="height: 100rpx;" @click="create">
			创建新房间
		</view>
	</view>
</template>

<script>
	import $H from '@/common/request.js';
	export default {
		data() {
			return {
				list: []
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			// 跳转直播间
			goLive(sid){
				// console.log(sid);
				let options = {
					mode:'SD',
					position:"back",
					beauty:1,
					whiteness:1
				}
				$H.post('/live/resave',{live_id:sid}).then(res => {
					// console.log(res);return
					let datas={}
					datas.data=res.data
					datas.sign=res.sign
					uni.navigateTo({
						url: `../liveroom/liveroom?options=${JSON.stringify(options)}&data=${encodeURIComponent(JSON.stringify(datas))}`,
					});
				})
				
				uni.navigateTo({
					url: ''
				});
			},
			// 创建新的直播间
			create(){
				uni.navigateTo({
					url: '../create-live/create-live'
				});
			},
			init() {
				$H.get('/live/seeLive', {
					token: true
				}).then(res => {
					// console.log(res);
					this.list = res.rows
				})
			}
		}
	}
</script>

<style>

</style>
